home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6143 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  990 b 

  1. Path: news.Stanford.EDU!usenet
  2. From: Ramana Reddy Kurri <kurri@leland.Stanford.EDU>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: OOPS! - Re: How to delete array of pointers?
  5. Date: 12 Feb 1996 01:49:54 GMT
  6. Organization: Stanford University
  7. Message-ID: <4fm6c2$an8@nntp.Stanford.EDU>
  8. References: <4fgvsu$5q4@eng_ser1.erg.cuhk.hk> <4fi8rd$738@reader2.ix.netcom.com> <4fkv8j$kb@cloner3.netcom.com>
  9. NNTP-Posting-Host: elaine11.stanford.edu
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.12 (X11; I; SunOS 4.1.4 sun4m)
  14. X-URL: news:4fkv8j$kb@cloner3.netcom.com
  15.  
  16. This is one way to return memory  to heap for a two dimensional array.
  17.  
  18.         int **arr;
  19.         arr = new int*[10];
  20.  
  21.         for(int i=0; i<10; i++)
  22.                 arr[i] = new int[10]; 
  23.  
  24.         // Do whatever you want....
  25.  
  26.         first delete the memory you have allocated to arr[i] and 
  27.     then deallocate the memory for arr
  28.  
  29.         for(int j=0; j<10; j++)
  30.             delete [] arr[j];
  31.  
  32.         delete [] arr;
  33.  
  34. --Ramana
  35.  
  36.